package org.example.webserver.service.serviceImpl;

import jakarta.annotation.Resource;
import jakarta.annotation.Resources;
import org.example.webserver.dao.UserDao;
import org.example.webserver.pojo.User;
import org.example.webserver.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;
    @Override
    public User loginService(String user, String password) {
        User user_0=userDao.findByUserAndPassword(user,password);
        if(user_0!=null){
            user_0.setPassword("");
        }
        return user_0;
    }

    @Override
    public User registService(User user) {
        if(userDao.findByUser(user.getUser())==null){
            user.setUser_group("user");
            User newUser=userDao.save(user);
            newUser.setPassword("");
            return newUser;
        }else{
            return null;
        }
    }

    @Override
    public User toBeMerchant(User user) {
        User user1=userDao.findByUser(user.getUser());
        user1.setUser_group("merchant");
        userDao.save(user1);
        user1.setPassword("");
        return user1;
    }
}
